// --- Mock Data Structure ---
const getPatientProfileMockData = (patientId) => {
    // 实际业务中，根据 patientId 调用 API 获取数据
    return {
      base: {
        id: patientId,
        name: '王梓涵',
        gender: '女',
        age: 16,
        phone: '138****8888',
        doctor: '魏医生',
        initialVisitDate: '2025-01-10',
        nextReviewDate: '2026-01-15',
        source: '线上平台',
        remark: '隐适美初诊，家长非常关注矫正进度。',
      },
      stats: {
        totalVisits: 12,
        totalFee: '4.8', // 万
        projectCount: 1, // 进行中的项目数
        lastVisitDate: '2025-11-20',
        imageCount: 18,
      },
      records: [
        { recordId: 'REC0012', date: '25-11-20', project: '隐适美复诊 (11/40)', summary: '更换牙套，附件检查，无异常。', status: '已完成', statusClass: 'finish' },
        { recordId: 'REC0011', date: '25-10-18', project: '牙周基础治疗', summary: '深度洁牙，牙周袋清理，出血控制。', status: '已完成', statusClass: 'finish' },
        { recordId: 'REC0010', date: '25-09-01', project: '托槽设计初稿', summary: '设计初稿已完成，待家长确认。', status: '草稿', statusClass: 'draft' },
      ],
      imageSamples: [
        'https://picsum.photos/id/101/100/100',
        'https://picsum.photos/id/102/100/100',
        'https://picsum.photos/id/103/100/100',
        'https://picsum.photos/id/104/100/100',
        'https://picsum.photos/id/105/100/100',
        'https://picsum.photos/id/106/100/100',
      ]
    };
  };
  
  
  Page({
    data: {
      profile: {},
      currentTab: 'records', // 默认显示病例
      patientId: null,
    },
  
    onLoad(options) {
      const id = options.id || 'P01555'; // 从URL获取患者ID
      this.setData({ patientId: id });
      this.fetchProfileData(id);
    },
  
    // 模拟数据加载函数
    fetchProfileData(id) {
      // 实际业务中：wx.showLoading(); api.getPatientProfile(id).then(...)
      const data = getPatientProfileMockData(id);
      this.setData({ profile: data });
      // wx.hideLoading();
    },
  
    // Tab 切换
    switchTab(e) {
      this.setData({ currentTab: e.currentTarget.dataset.tab });
    },
  
    // 快捷操作
    callPatient() {
      wx.makePhoneCall({ phoneNumber: this.data.profile.base.phone });
    },
  
    createNewRecord() {
      // 跳转到创建诊疗记录页，并带上患者 ID
      wx.navigateTo({ 
        url: `/pages/treatment-record/treatment-record?patientId=${this.data.patientId}` 
      });
    },
  
    // 查看病例详情 (跳转到病例管理页)
    viewCaseDetail(e) {
      const recordId = e.currentTarget.dataset.id;
      wx.navigateTo({
        url: `/pages/case-management/case-management?patientId=${this.data.patientId}&recordId=${recordId}`
      });
    },
    
    // 预览影像
    previewImage(e) {
      const current = e.currentTarget.dataset.src;
      wx.previewImage({
        current: current,
        urls: this.data.profile.imageSamples 
      });
    }
  });